var mongoose = require('mongoose');
const Schema = mongoose.Schema;

/*
 网页导出链接
 status 0 移除， 1 可用, -1 发出
 createTime: 表示发出邮件的时间
 */
export const InUrlSchema = new Schema({
    url: String,
    createTime: {
        type: Date,
        default: Date.now(),
    },
    domain: String,
    email: String,
    status:{
        type: Number,
        default: 1
    }
});
// InUrlSchema.index({url: 1}, {unique: true});
// InUrlSchema.index({domain: 1}, {unique: true});
// InUrlSchema.index({email: 1}, {unique: true});

// InUrlSchema.pre('validate', function(next) {
//     if (this.createTime) {
//         this.createTime = this.createTime + 60*60*1000*8;
//     } else {
//         if (this.isNew){
//             this.createTime = Date.now() + 60*60*1000*8;
//         }
//     }
//     if (this.successTime) {
//         this.successTime = this.successTime + 60*60*1000*8;
//     }
//     next();
// });

export const InUrlModel = mongoose.model('in_url', InUrlSchema);

// InUrlModel.on('index', (err) => {
//     if(err)console.log('OutUrlModel create index failure');
//     else console.log('OutUrlModel create index success');
// })